<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>批量修改微信信息</title>
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../assets/style/admin.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <script src="../assets/layui/layui.js"></script>
    <script src="../assets/js/common.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../common/header.js"></script>
    <!-- 内容主体区域 -->
    <div id="LAY_app_body">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body">
                            <form class="layui-form" action="" onsubmit="return false;">
                                <fieldset class="layui-elem-field">
                                    <legend>批量设置信息</legend>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">设置</label>
                                        <div class="layui-input-block" id="exist_group">
                                            <input type="checkbox" name="change_nickname" title="微信昵称" value="1" class="wechatSet">
                                            <input type="checkbox" name="change_headimg" title="微信头像" value="1" class="wechatSet">
                                            <input type="checkbox" name="change_snsimg" title="朋友圈封面" value="1" class="wechatSet">
                                            <input type="checkbox" name="change_sign" title="个性签名" value="1" class="wechatSet">
                                            <input type="checkbox" name="change_sex" title="性别：男" value="1" class="wechatSet">
                                            <input type="checkbox" name="change_sex" title="性别：女" value="2" class="wechatSet">
                                            <br>
                                            <input type="checkbox" name="change_sns_range" title="朋友圈全部可见" value="1" class="wechatSet">
                                            <input type="checkbox" name="change_sns_range" title="朋友圈半年可见" value="2" class="wechatSet">
                                            <input type="checkbox" name="change_sns_range" title="朋友圈一个月可见" value="4" class="wechatSet">
                                            <input type="checkbox" name="change_sns_range" title="朋友圈三天可见" value="3" class="wechatSet">
                                        </div>
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">重复修改</label>
                                            <div class="layui-input-block" id="exist_group">
                                                <input type="checkbox" name="change_again" title="是" value="1">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-field-box">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">可选组</label>
                                            <div class="layui-input-block" id="availableGroups">
                                                <div class="layui-form-mid">无</div>
                                            </div>
                                            <div class="layui-form-mid layui-text"><a href="../../code/group/index.html" target="_blank"><i class="layui-icon layui-icon-about" style="color: #1E9FFF;"></i>微信组管理</a></div>
                                        </div>
                                    </div>
                                </fieldset>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <a class="layui-btn" lay-submit lay-filter="formSubmit">确认修改</a>
                                        <a class="layui-btn layui-btn-primary" href="../../code/wechat/index.html">返回列表</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        layui.use(['form'], function(){
            var $ = layui.$
                ,form = layui.form;

            form.verify({

            });

            var getExistGroup, getWechatSet;

            getWechatSet = function () {
                // var objs = $('.existGroup');
                var objs = $('.wechatSet:checked');
                var hasSet = false;
                $.each(objs, function (index, obj) {
                    hasSet = true;
                });
                return hasSet;
            };

            getExistGroup = function () {
                // var objs = $('.existGroup');
                var objs = $('.wechatGroup:checked');
                var hasGroup = false;
                $.each(objs, function (index, obj) {
                    hasGroup = true;
                });
                return hasGroup;
            };


            //监听提交
            form.on('submit(formSubmit)', function(data){
                var hasSet = getWechatSet();
                if (!hasSet) {
                    layer.msg('请选择要设置的选项', {icon: 5});
                    return false
                }

                var hasGroup = getExistGroup();
                if (!hasGroup) {
                    layer.msg('请选择执行的微信组', {icon: 5});
                    return false
                }
                layer.msg('提交中', {
                    shadeClose: false
                    ,icon: 16
                    ,shade: 0.01
                });
                $.ajax({
                    type: "POST",
                    url: "/batch_change_wechat_info/save",
                    data: data.field,
                    success:function(response){
                        var dataObj=$.parseJSON(response);
                        if (dataObj.code===0) {
                            layer.msg(dataObj.msg, {icon: 6});
                            var targetUrl = '/batch_change_wechat_info/index';
                            setTimeout(function(){
                                location.href = targetUrl;
                            }, 1000);
                        } else {
                            layer.msg(dataObj.msg, {icon: 5});
                        }
                    },
                    error: function (request, status, error) {
                        layer.msg('哦噢，网络开小差了', {icon: 5});
                    }
                });
                return false;
            });
        });
    </script>
</div>
</body>
</html>
